Page({
  data: {
    images: [],
    currentPair: [],
    currentIndex: 0 // 每次显示两张，index 表示第几对图
  },

  onLoad(options) {
    const imgs = JSON.parse(decodeURIComponent(options.images));
    this.setData({
      images: imgs
    }, () => {
      this.updateCurrentPair();
    });
  },

  updateCurrentPair() {
    const { images, currentIndex } = this.data;
    const start = currentIndex * 2;
    const pair = [images[start], images[start + 1]].filter(Boolean);
    this.setData({ currentPair: pair });
  },

  onNextPage() {
    const maxIndex = Math.floor(this.data.images.length / 2);
    if (this.data.currentIndex < maxIndex) {
      this.setData({ currentIndex: this.data.currentIndex + 1 }, () => {
        this.updateCurrentPair();
      });
    }
  },

  onPrevPage() {
    if (this.data.currentIndex > 0) {
      this.setData({ currentIndex: this.data.currentIndex - 1 }, () => {
        this.updateCurrentPair();
      });
    }
  }
});
